package actions;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.*;
import java.sql.*;

import model.ReviewerModel;
import model.StudentModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;

public class ChooseAnalyticsAction extends Action {
    // is there a way to make this global for the application
    public final int REVIEW_PROCESS_THRESHOLD = 3;

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws DbException {
        // gets analytics choice
        String choice = request.getParameter("choice");
        String path = "analytic";
        // set choice to request scope
        request.getSession().setAttribute("choice", choice);
        
        // gets analytics data from the DB
        // disciplines
        if(choice.equals("discipline")){
            ResultSet disciplines = StudentModel.getDisciplineAnalytics();
            request.getSession(false).setAttribute("analyticsRowSet", disciplines);
            path = "analytic";
        // specializations
        }else if(choice.equals("specialization")){
            ResultSet disciplines = StudentModel.getSpecializationAnalytics();
            request.getSession(false).setAttribute("analyticsRowSet", disciplines);
            path = "analytic";
        // reviewers
        }else{
            ResultSet reviewers = ReviewerModel.getReviewerAnalytics();
            request.getSession(false).setAttribute("analyticsRowSet", reviewers);
            path = "reviewer";
        }
        
        // maps to page
        return mapping.findForward(path);
        
    }
}
